package clinic.ms.service;

import clinic.ms.entity.Admin;
import clinic.ms.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;

@Service
public class AdminServiceImpl{

    @Autowired
    AdminMapper adminMapper;

    // 根据名称查询，返回一个
    public Admin queryAdByName(String userName){
        return adminMapper.queryAdByName(userName);
    }


    //根据名称模糊查询
    public ArrayList<Admin> queryAdByNames(String userName) {
        return adminMapper.queryAdByNames(userName);
    }

    public String insertAdmin(Admin admin){
        if(adminMapper.insertAdmin(admin) != 1){ // 插入失败会报错,但好像不会插入失败，除非同时插入两个
            return null;
        }
        else return "true";
    }

    public boolean deleteAdByName(String userName) throws Exception{
        // 插入成功返回1，删除不存在的返回0，否则报错
        return adminMapper.deleteAdByName(userName) == 1;
    }


    public boolean updateAdByName(Admin admin) {
        return adminMapper.updateAdByName(admin) == 1;
    }


}
